class Solution {
public:
    bool lemonadeChange(vector<int>& bills)
    {
        int five = 0, ten = 0;
        int sum = 0;
        for (int i = 0; i < bills.size(); i++)
        {
            if (bills[i] == 5)
            {
                five++;
            }
            else if (bills[i] == 10)
            {
                if (five) five--, ten++;
                else return false;
            }
            else if (bills[i] == 20)
            {
                if (ten)
                {
                    if (five)ten--, five--;
                    else return false;
                }
                else
                {
                    if (five >= 3) five -= 3;
                    else return false;
                }

            }
        }
        return true;
    }
};